<?php
namespace app\api\controller;

use think\Controller;
use think\Request;
use think\Db;
use think\facade\Url;

use app\api\model\SignSet;
use app\api\model\MemberInfo;
use app\api\model\Sign as SM;

class Sign extends Common
{
    private $noCheckAction = [];//不需要验证的方法
    
    public function initialize(){
        parent::initialize();
        $this->doCheckAuth($this->noCheckAction);
    }
    /**
    * 获取签到列表
    */
    public function signList(){
       $member = $this->member;
       $mid = $member['id'];
       $model = New SignSet;
       $list = $model->_list($mid);
       return apiSuccess($list);
    }

    /**
    * 会员签到
    */
    public function signIn(){
        $member = $this->member;
        $mid = $member['id'];
        $model = New SM;
        $request = $this->request->post();
        /*if(empty($request['day'])){
            return apiError('缺少参数');
        }*/
        //$day = (int)$request['day'];
        $day = 0;
        $ret = $model->_signIn($mid ,$day);
        if(!$ret){
            return apiError($model->getError());
        }
        
        $model = New SignSet;
        $list = $model->_list($mid);
        $model = new MemberInfo;
        $memberInfo = $model->_getInfoByMid($mid);
        $sign_continuity_num = $memberInfo['sign_continuity_num'];
        
        return apiSuccess(['gold'=>$ret, 'sign_continuity_num'=>$sign_continuity_num, 'list'=>$list],'签到成功');
    }


    public function apple_store()
    {

       // $member = $this->member;
      //  $mid = $member['id'];
//
        //苹果内购的验证收据
        $receipt_data = input('post.apple_receipt');

        // 验证支付状态
        $result=validate_apple_pay($receipt_data);
        dump($result);die;
        if($result['status']){
            // 验证通过 此处可以是修改数据库订单状态等操作
             echo 123;
        }else{
            echo 456;
        }
            // 验证不通过
        }


   
}